package com.zhangshanfeng.test3;

import java.sql.Time;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/*
面试题代码
 */
public class Test {
    public static void main(String[] args) {
        //    参数一：核心线程数量
//    参数二：最大线程数
//    参数三：空闲线程最大存活时间
//    参数四：时间单位
//    参数五：任务队列
//    参数六：创建线程工厂
//    参数七：任务的拒绝策略

        ThreadPoolExecutor pool = new ThreadPoolExecutor(1,
                2,
                0,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        pool.execute(new TaskThread("任务1"));
        pool.execute(new TaskThread("任务2"));
        pool.execute(new TaskThread("任务3"));
        pool.execute(new TaskThread("任务4"));
        pool.execute(new TaskThread("任务5"));
        pool.execute(new TaskThread("任务6"));
        pool.execute(new TaskThread("任务7"));
        pool.execute(new TaskThread("任务8"));
        pool.shutdownNow();


    }
}
